package org.example.myleet.p1598;

import java.util.Deque;
import java.util.LinkedList;

public class Solution {
//    public int minOperations(String[] logs) {
//        int level = 0;
//        for (String log : logs) {
//            if (log.startsWith("../")) {
//                if (level > 0) {
//                    --level;
//                }
//            } else if (log.startsWith("./")) {
//                //ignore
//            } else {
//                ++level;
//            }
//        }
//        return level;
//    }

    public int minOperations(String[] logs) {
        Deque<String> stack = new LinkedList<>();
        for (String log : logs) {
            if ("../".equals(log)) {
                if (stack.size() > 0) {
                    stack.pop();
                }
            } else if ("./".equals(log)) {
                //ignore
            } else {
                stack.push(log);
            }
        }
        return stack.size();
    }
}
